import { SetMetadata } from '@nestjs/common';
import { IS_PUBLIC_KEY, PERMS_KEY, ROLES_KEY } from '../../util/constants';
// jwt是否不做检查,表示公共接口
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);

export type PermsType = string | string[] | string[][];
export type RolesType = string | string[] | string[][];
// 权限
// 参考 https://www.npmjs.com/package/express-jwt-permissions
// 'read'  单个权限
// ['read', 'write']  Required: "read" AND "write"
//  [ ['admin'], ['read', 'write']]  Required: "admin" OR ("read" AND "write")
export const HasPerms = (perms: PermsType) => SetMetadata(PERMS_KEY, perms);
// 角色
export const HasRoles = (roles: RolesType) => SetMetadata(ROLES_KEY, roles);
